#!/usr/bin/python

import json
import re
import commands


def hpux_mem_get():
    try:
        (status, output) = commands.getstatusoutput('/usr/contrib/bin/machinfo | grep Memory')
        print output
        results_lt = re.split(r"\(|\)| ", output)
        hpux_mem_str = results_lt[4]
        hpux_mem_float = float(hpux_mem_str)
        hpux_mem = round(hpux_mem_float)
    except Exception:
        hpux_mem = ""

    return hpux_mem


def hpux_processor_get():
    try:
        (status, output) = commands.getstatusoutput('/usr/contrib/bin/machinfo | grep cores | tail -1')
        print output
        results_lt = re.split(r" ", output)
        hpux_processor = results_lt[-2]
        hpux_processor = float(hpux_processor)
    except Exception:
        hpux_processor = ""

    return hpux_processor
    print hpux_processor


def main():
    hpux_mem = hpux_mem_get()
    hpux_processor = hpux_processor_get()

    print json.dumps({
        'hpux_processor': hpux_processor,
        'hpux_mem': hpux_mem,
         }
         )


if __name__ == '__main__':
    main()
